package com.librarySystem.action;

import java.util.LinkedList;
import java.util.List;

import com.librarySystem.dto.PageDTO;
import com.librarySystem.dto.QueryRestrictionsDTO;
import com.librarySystem.entity.Book;
import com.librarySystem.service.BookServiceInterface;

public class BookAction extends BaseLibrarySystemAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Book book;
	private List<Book> books;
	private QueryRestrictionsDTO queryRestrictionsDTO;
	private PageDTO pageDTO;
	private BookServiceInterface bookService;
	private boolean msg;
	private boolean noBook;

	public String find(){
		if(pageDTO == null){
			pageDTO = new PageDTO();
		}
		pageDTO.setPageCount(bookService.findCount(queryRestrictionsDTO));
		books = bookService.find(queryRestrictionsDTO,pageDTO);
		
		if(books == null){
			noBook = true;
		}
		return SUCCESS;
	}
	public String update(){
		books = new LinkedList<Book>();
		Book b = bookService.update(book);
		if (b != null) {
			books.add(b);
			if ( b.getCount() == 0 && book.getCount() == -1){
				msg = true;
			}
		}
		return "updateSuccess";
	}
	

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public List<Book> getBooks() {
		return books;
	}

	public void setBooks(List<Book> books) {
		this.books = books;
	}

	public QueryRestrictionsDTO getQueryRestrictionsDTO() {
		return queryRestrictionsDTO;
	}

	public void setQueryRestrictionsDTO(QueryRestrictionsDTO queryRestrictionsDTO) {
		this.queryRestrictionsDTO = queryRestrictionsDTO;
	}

	public BookServiceInterface getBookService() {
		return bookService;
	}

	public void setBookService(BookServiceInterface bookService) {
		this.bookService = bookService;
	}
	public boolean isMsg() {
		return msg;
	}
	public void setMsg(boolean msg) {
		this.msg = msg;
	}
	public boolean isNoBook() {
		return noBook;
	}
	public void setNoBook(boolean noBook) {
		this.noBook = noBook;
	}
	public PageDTO getPageDTO() {
		return pageDTO;
	}
	public void setPageDTO(PageDTO pageDTO) {
		this.pageDTO = pageDTO;
	}

	
}
	